package com.example.mapper;

import com.example.pojo.Messages;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessagesMapper {
    @Select("SELECT * FROM messages WHERE sender_id = #{senderId} ORDER BY timestamp DESC")
    List<Messages> listBySenderId(@Param("senderId") Integer senderId);

    @Insert("INSERT INTO messages (conversation_id, sender_id, content, timestamp, type) " +
            "VALUES (#{conversationId}, #{senderId}, #{content}, #{timestamp}, #{type})")
    @Options(useGeneratedKeys = true, keyProperty = "msgId")
    void insert(Messages message);
}

